package game.farming.model;

import game.farming.ui.Player;
import java.util.Vector;

public class Table{
	private String name;
	private Vector<Player> players;
	private Dice dice;
	private Deck<OptionToBuy> optionToBuys;
	private Deck<FarmersFate> farmersFates;
	private Deck<OperatingExpense> operatingExpenses;
	private Board board;
	
	public Table(String name){
		this.name = name;
		players = new Vector<Player>();
		init();
	}
	
	public void addPlayer(Player player){
		players.add(player);
	}
	
	public OptionToBuy drawOtb(){
		if(optionToBuys.size() > 0){
			return optionToBuys.pop();
		}
		else{
			return OptionToBuy.OTB_R4;
		}
	}
	
	public String getName(){
		return name;
	}
	
	public void setName(String name){
		this.name = name;
	}
	
	public Vector<Player> getPlayers(){
		return players;
	}
	
	public void setPlayers(Vector<Player> players){
		this.players = players;
	}
	
	public Dice getDice(){
		return dice;
	}
	
	public void setDice(Dice dice){
		this.dice = dice;
	}
	
	public Deck<OptionToBuy> getOptionToBuys(){
		return optionToBuys;
	}
	
	public void setOptionToBuys(Deck<OptionToBuy> optionToBuys){
		this.optionToBuys = optionToBuys;
	}
	
	public Deck<FarmersFate> getFarmersFates(){
		return farmersFates;
	}
	
	public void setFarmersFates(Deck<FarmersFate> farmersFates){
		this.farmersFates = farmersFates;
	}
	
	public Deck<OperatingExpense> getOperatingExpenses(){
		return operatingExpenses;
	}
	
	public void setOperatingExpenses(Deck<OperatingExpense> operatingExpenses){
		this.operatingExpenses = operatingExpenses;
	}
	
	public Board getBoard(){
		return board;
	}
	
	public void setBoard(Board board){
		this.board = board;
	}
	
	private void init(){
		board = new Board();
		dice = new Dice(1);
		
		optionToBuys = new Deck<OptionToBuy>();
		for(int i = 0; i < 4; i++){
			optionToBuys.push(OptionToBuy.OTB_HAY);
			optionToBuys.push(OptionToBuy.OTB_GRAIN);
			optionToBuys.push(OptionToBuy.OTB_FRUIT);
			optionToBuys.push(OptionToBuy.OTB_COWS);
			optionToBuys.push(OptionToBuy.OTB_TRACTOR);
			optionToBuys.push(OptionToBuy.OTB_HARVESTOR);
			optionToBuys.push(OptionToBuy.OTB_R1);
			optionToBuys.push(OptionToBuy.OTB_R2);
			optionToBuys.push(OptionToBuy.OTB_R3);
			optionToBuys.push(OptionToBuy.OTB_R4);
		}
		optionToBuys.shuffle();
	}

	public String restartGame() {
		init();
		for( Player p : players ){
			p.gameInit();
		}
		return "";
	}
}
